const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeList:[{name:'闲置设备',shid:0},{name:'企业余料',shid:1}],
    shid:0,
    typename:'闲置设备',
    ComName:'',
    Linkman:'',
    Mobile:'',
    Description:'',
    FjLoginLog:wx.getStorageSync('FjLoginLog'),    
  },
  ComName:function (e) {
    this.setData({
      ComName: e.detail.value
    })
  },
  Linkman:function (e) {
    this.setData({
      Linkman: e.detail.value
    })
  },
  Mobile:function (e) {
    this.setData({
      Mobile: e.detail.value
    })
  },
  Description:function (e) {
    this.setData({
      Description: e.detail.value
    })
  },    
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {    
    if (app.checkFjLogin()) {
      this.setData({
        FjLoginLog: wx.getStorageSync('FjLoginLog')
      })
      var that = this
      var api_input ={
        uid:this.data.FjLoginLog.UID,
        upwd:this.data.FjLoginLog.UPwd      
      }
      app.getDaoPost('api/FeijiuApp/Post_FJ_UserInfoByUID',api_input,function (r) {
        var udata = JSON.parse(app.aesDec(r.data));
        that.setData({
          ComName:udata.Uinfo[0].ComName,
          Linkman:udata.Uinfo[0].Linkman,
          Mobile:udata.Uinfo[0].Mobile
        })
      })      
    }else{
      wx.redirectTo({ url: '../../pages/login/index' }); 
    }
  },
  zctab:function (e) {
    if (this.data.shid != e.currentTarget.dataset.shid) {
      this.setData({
        shid:e.currentTarget.dataset.shid,
        typename:e.currentTarget.dataset.name
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // },
  zcbtn:function () {
    if (this.data.Linkman.length < 1) {
      this.checkInput('请输入联系人姓名')
      return false;
    }       
    if (this.data.Mobile.length < 1) {
      this.checkInput('请输入联系人姓名')
      return false;
    }
    if (this.data.ComName.length < 1) {
      this.checkInput('请输入公司名称')
      return false;
    }
    if (this.data.Description.length < 1) {
      this.checkInput('请输入产品描述')
      return false;
    }

    if (app.checkFjLogin()) {    
      var strJson = {
        GB_Class_ID:21,
        Title:'商机快速发布',
        Content:this.data.typename+':'+this.data.Description,
        Company:this.data.ComName,
        LinkPerson:this.data.Mobile+''+this.data.Linkman,
        Telphone:this.data.Mobile,
        Mobile:this.data.Mobile,
        JoinTime:app.getCurrentDate(),
        Uid:this.data.FjLoginLog.UID        
      }
    }else{
      var strJson = {
        GB_Class_ID:21,
        Title:'商机快速发布',
        Content:this.data.typename+':'+this.data.Description,
        Company:this.data.ComName,
        LinkPerson:this.data.Mobile+''+this.data.Linkman,
        Telphone:this.data.Mobile,
        Mobile:this.data.Mobile,
        JoinTime:app.getCurrentDate()
      }      
    }

    var api_input = {
      strRSA:app.data.strRSA,
      strJson:JSON.stringify(strJson)
    }
    var that = this;
    app.getDaoPostOld('api/FeijiuApp/Add_FabuZc',api_input,function (r) {
      if (r.code == 200) {
        wx.navigateTo({
          url: 'fbSuccess?shid=liuyan'
        })
      }else{
        that.checkInput('发布失败,请联系客服人员或者人工发布');
      }

    })
  },


  checkInput:function (tishi) {
    wx.showModal({
        title: 'Feijiu网提示您',
        content: tishi,
        showCancel: false,
        confirmText: '确定',
        confirmColor: '#3CC51F'
    }) 
  },  
})

